//
//  BaseViewController.m
//  NBProduct
//
//  Created by ping on 15/8/19.
//  Copyright (c) 2015年 ping. All rights reserved.
//

#import "BaseViewController.h"





@interface BaseViewController ()

@end
//#warning 请修改此处 URL 地址
//#define ZFBkServerUrl  @"http://csfwqw.6655.la:18888/cop/pay/payhook1.action"
#define ZFBkServerUrl   [NSString stringWithFormat:@"http://%@/pay/payhook1.action",IP]
@implementation BaseViewController

-(void)viewDidLoad {
    
   
    [super viewDidLoad];
    [self ksc];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 15, 18)];
    [btn addTarget:self action:@selector(goBackTo) forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:[UIImage imageNamed:@"backItem" ] forState:UIControlStateNormal];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    self.navigationItem.leftBarButtonItem = backItem;

}

-(void)goBackTo{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)drawView{
    
}
-(void)drawBackTiShiButton{
    
}

-(void)requestData{
    
  
    
}
-(void)ksc{
    if (KScreenHeight == 480 ) {
        _kscH = 1;
        _kscW = 1;
    }
    else
    {
        _kscH = KScreenHeight / 568;
        _kscW = KScreenWidth / 320;
    }
}

-(void)drawNavWithTitle:(NSString *)Title{
    UIView *labNav = [[UIView alloc]initWithFrame:CGRectMake(0, 0,KScreenWidth , 64+14)];
    labNav.backgroundColor = ZONGCOLOR;
    [self.view addSubview:labNav];
    
    UILabel* lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 30,KScreenWidth,  16)];
    lab.textAlignment = NSTextAlignmentCenter;

    lab.textColor = [UIColor whiteColor];
    lab.font = [UIFont fontWithName:TextJiaCu size:18.0f];
    lab.text = Title;
    lab.backgroundColor = [UIColor clearColor];
    [labNav addSubview:lab];
    
    UILabel *infomationLab = [[UILabel alloc] initWithFrame:CGRectMake(0, lab.bottom +14, KScreenWidth, 22 )];
    infomationLab.backgroundColor = XiaHuaXianCOLOR;
    infomationLab.textAlignment = NSTextAlignmentCenter;
    infomationLab.font = [UIFont systemFontOfSize:12.0];
    infomationLab.text = @"您好,Z0001(金砖会员)现金币: ￥222.00 注册币: ￥22.00";
    [labNav addSubview:infomationLab];
    
}

-(void)drawNavWithTitle:(NSString *)Title WithColor:(UIColor*)color{
    UILabel *labNav = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,KScreenWidth , 64)];
    labNav.backgroundColor = color;
    [self.view addSubview:labNav];
    UILabel* lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,180 ,  27)];
    lab.center = CGPointMake(KScreenWidth  / 2 , 43) ;
    lab.textAlignment = NSTextAlignmentCenter;
    lab.textColor = ZONGCOLOR;
    lab.font = [UIFont boldSystemFontOfSize:18.0];
    lab.text = Title;
    lab.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lab];
    
    UILabel *fenggeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 63, KScreenWidth, 0.5)];
    fenggeLab.backgroundColor = NavColor;
    [self.view addSubview:fenggeLab];
}
-(void)yangCheDrawNavWithTitle:(NSString *)Title WithColor:(UIColor*)color{
    UILabel *labNav = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,KScreenWidth , 64)];
    labNav.backgroundColor = color;
    [self.view addSubview:labNav];
    UILabel* lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,180 ,  27)];
    lab.center = CGPointMake(KScreenWidth  / 2 , 43) ;
    lab.textAlignment = NSTextAlignmentCenter;
    lab.textColor = [UIColor whiteColor];
  //  lab.font = [UIFont boldSystemFontOfSize:18.0];
    lab.text = Title;
    lab.font = [UIFont fontWithName:TextJiaCu size:18.0];
    lab.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lab];
    
    UILabel *fenggeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 63, KScreenWidth, 0.5)];
    fenggeLab.backgroundColor = NavColor;
    [self.view addSubview:fenggeLab];
}
-(UIBarButtonItem *)drawKuaiDiBackButton{
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [backButton setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    return backItem;
}
-(void)drawBackButton{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 15, 60, 44)];
    //    [btn setImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal];
    //    [btn setImageEdgeInsets:UIEdgeInsetsMake(5, -10, 0, 0)];
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchDown];
    UILabel *backLabel = [[UILabel alloc]initWithFrame:CGRectMake( 20, 5, 40, 34)];
//    backLabel.text = @"返回";
    backLabel.font = [UIFont systemFontOfSize:20];
    backLabel.textColor = [UIColor whiteColor];
    //35  52
    UIImageView *btnImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 12 , 20)];
    [btnImage setImage:[UIImage imageNamed:@"arrow_left"]];
    [btn addSubview:btnImage];
    [btn addSubview:backLabel];
    [self.view addSubview:btn];
}
-(void)drawBackButtonTwo{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 60, 44)];

    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchDown];
    
    
    UIImageView *btnImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 10, 15 , 24)];
    [btnImage setImage:[UIImage imageNamed:@"箭头"]];
    [btn addSubview:btnImage];
  
    [self.view addSubview:btn];
}

-(UIImage *) getImageFromURL:(NSURL*)url {
    
    NSLog(@"执行图片下载函数");
    
    UIImage * result;
    
    NSData * data = [NSData dataWithContentsOfURL:url];
    
    result = [UIImage imageWithData:data];
    
    return result;
    
}

-(void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}
//返回字符高度
-(CGSize)setFrame:(NSString *)text fontSize:(CGFloat)size andBiggestWidth:(CGFloat)width{
    CGSize maxSize = CGSizeMake(KScreenWidth - width, 1000);
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:size]};
    NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin;
    CGSize labelsize = [text boundingRectWithSize:maxSize options:options attributes:dic context:nil].size;
    return labelsize;
}
#pragma mark 返回评论的NSAttributedString回复
-(NSAttributedString *)returnCellText:(NSString *)nameStr anwserName:(NSString *)anwserName andAnwserText:(NSString *)anwsetText{
    NSString *newN = [nameStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    
    NSString *toStr = anwserName;
    NSString *newTo = [toStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSString *anserStr =anwsetText;
    NSString *newans = [anserStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSString *hui = @"回复";
    
    NSString *newStr = [NSMutableString stringWithFormat:@"%@%@%@ :%@",newN,hui,newTo,newans];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:newStr];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:26/255.0 green:141/255.0 blue:255/255.0 alpha:1] range:NSMakeRange(0, newN.length)];
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(newN.length, hui.length)];
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:26/255.0 green:141/255.0 blue:255/255.0 alpha:1] range:NSMakeRange(newN.length+hui.length, newTo.length)];
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(newN.length+hui.length+newTo.length, newans.length+2)];
    
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.0] range:NSMakeRange(0, newStr.length)];
    
    return str;
}

-(NSAttributedString *)returnCellText:(NSString *)text AndNumStr:(NSString *)numStr andPingfenColor:(UIColor *)pColor andOtnerColor:(UIColor *)otherColor{
    
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];
    [str addAttribute:NSForegroundColorAttributeName value:pColor range:NSMakeRange(3, 4)];
    
    [str addAttribute:NSForegroundColorAttributeName value:otherColor range:NSMakeRange(0, 2)];
    
    [str addAttribute:NSForegroundColorAttributeName value:otherColor range:NSMakeRange(9, text.length - 9)];
    return str;
}
#pragma mark userdefor

-(NSString *)defaultLoadUserName{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"userName"];
}

-(NSString *)defaultLoadPortrait{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"portrait"];
}

-(NSString *)defaultLoadlongitude
{
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"longitude"];
    
}

-(NSString *)defaultLoadlatitude
{
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"latitude"];
    
}
-(NSString *)defaultLoadcityname
{
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"cityname"];
    
}
-(NSString *)defaultLoadisRegistXiaoQu{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"isRegistXiaoQu"];
}
-(NSString *)defaultLoadcityCode
{
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"cityCode"];
    
}


-(NSString *)defaultLoadcityId
{
    
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"city"];
    
}
-(NSString *)defaultLoadFangWuAddress{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"fangWuAddress"];
}
-(void)defaultSaveUserName:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"userName"];
    
    [defaults synchronize];
}
-(void)defaultSaveUserIsRegistXiaoQu:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"isRegistXiaoQu"];
    
    [defaults synchronize];
}
-(void)defaultSaveIsXiaoQuYeZhu:(NSString *)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"isXiaoQuYeZhu"];
    
    [defaults synchronize];
}
-(void)defaultSavePortrait:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"portrait"];
    
    [defaults synchronize];
}

-(void)defaultSavecityName:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"cityname"];
    
    [defaults synchronize];
    
}
-(void)defaultSavecityCode:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"cityCode"];
    
    [defaults synchronize];
    
}

-(void)defaultSavecity:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"city"];
    
    [defaults synchronize];
    
}
-(void)defaultSavelongitude:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"longitude"];
    
    [defaults synchronize];
    
}

-(void)defaultSavelatitude:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"latitude"];
    
    [defaults synchronize];
    
}
-(void)defaultSaveFangWuAddress:(NSString *)a{
   
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"fangWuAddress"];
    
    [defaults synchronize];
}

-(NSString *)defaultLoadTokenId{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"deviceToken"];
}
-(void)defaultSaveTokenId:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"deviceToken"];
    
    [defaults synchronize];

}

-(NSString *)defaultTuiJianRenId{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"TuiJianRenId"];
}
-(void)defaultSaveTuiJianRenId:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"TuiJianRenId"];
    
    [defaults synchronize];
    
}

-(NSString *)defaultGongNengBiaoJi{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"GongNengBJ"];
}
-(void)defaultSaveGongNengBiaoJi:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"GongNengBJ"];
    
    [defaults synchronize];
    
}

//longintype
-(NSString *)defaultLonginType{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"LonginType"];
}
-(void)defaultSaveLonginType:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"LonginType"];
    
    [defaults synchronize];
    
}



//商户
-(NSString *)defaultShangHuId_chongYin{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"shangHuId_chongYin"];
}
-(void)defaultSaveShangHuId_chongYin:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"shangHuId_chongYin"];
    
    [defaults synchronize];

}

-(NSString *)defaultChanPinId_chongYin{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"chanPinId_chongYin"];
}
-(void)defaultSaveChanPinId_chongYin:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"chanPinId_chongYin"];
    
    [defaults synchronize];
}

-(NSString *)defaultPeiZhiId_chongYin{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"peizhiId_chongYin"];
}
-(void)defaultSavePeiZhiId_chongYin:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"peizhiId_chongYin"];
    
    [defaults synchronize];
}



//支付区别
-(NSString *)defaultZhiFuType{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"zhiFuType"];
}
-(void)defaultSaveZhiFuType:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"zhiFuType"];
    
    [defaults synchronize];
}

-(NSString *)returnNoNullStrWith:(NSString *)str{
    
    
    if ([str isKindOfClass:[NSNull class]] || [str isEqual:[
        NSNull null]] || [str isEqual:@"(null)"] || str == nil) {
        return @"";
    }else{
        return str;
    }
}
-(NSString *)defaultLoadIsXiaoQuYeZhu{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"isXiaoQuYeZhu"];
}
-(NSString *)defaultImageLong{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"imageLong"];
}
-(void)defaultSaveImageLong:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"imageLong"];
    
    [defaults synchronize];
}
-(NSString *)defaultImageWidth{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    return [defaults objectForKey:@"imageWidth"];
}
-(void)defaultSaveImageWidth:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"imageWidth"];
    
    [defaults synchronize];
}

-(NSString *)defaultMoRenAddressId{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"moRenAddressId"];
}
-(void)defaultSaveMoRenAddressId:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"moRenAddressId"];
    
    [defaults synchronize];

}

-(NSString *)defaultUserId{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"UserId"];
}
-(void)defaultSaveUserId:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"UserId"];
    
    [defaults synchronize];
}

-(NSString *)defaultBirthday{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"Birthday"];

}
-(void)defaultSaveBirthday:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"Birthday"];
    
    [defaults synchronize];

}

-(NSString *)defaultNiCheng{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"NiCheng"];
}
-(void)defaultSaveNiCheng:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"NiCheng"];
    
    [defaults synchronize];

}

-(NSString *)defaultPhone
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"Phone"];

}
-(void)defaultSavePhone:(NSString*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"Phone"];
    
    [defaults synchronize];
}
-(NSArray *)defaultChongZhiPhone
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"ChongZhiPhone"];
    
}
-(void)defaultSaveChongZhiPhone:(NSArray*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"ChongZhiPhone"];
    
    [defaults synchronize];
}

-(NSArray *)defaultShangChengSouSuoJiLU{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    
    return [defaults objectForKey:@"shangChengSouSuo"];

}
-(void)defaultSaveShangChengSouSuoJiLU:(NSArray*)a{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"shangChengSouSuo"];
    
    [defaults synchronize];
}


-(NSURL *)returenUrlWithStr:(NSString *)str{
    
    
//    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IPStr,str]];
    
    return nil;
}

-(BOOL)jianCeLogin{
    
     if (![[self defaultLoadUserName]isEqualToString:@""] && [self defaultLoadUserName]) {
         return YES;
     }else{
    
         UIAlertView *alertViw = [[UIAlertView alloc]initWithTitle:@"" message:@"请登录后操作" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往登录", nil];
         alertViw.tag = 99999;
         [alertViw show];
         
         return NO;
     }
}

-(BOOL)jianCePhone{
    if ([self jianCeLogin]) {
        if (![[self defaultPhone]isEqualToString:@""] && [self defaultPhone]) {
            return YES;
        }else{
            
            UIAlertView *alertViw = [[UIAlertView alloc]initWithTitle:@"" message:@"请绑定手机后操作" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往绑定", nil];
            alertViw.tag = 10001;
            [alertViw show];
            
            return NO;
        }
    }else{
        return NO;
    }
}

-(NSAttributedString *)returnPriceStr:(NSString *)price andOldPrice:(NSString *)oldPrice{
    NSString *priceStr = [NSString stringWithFormat:@"￥%@ ￥%@",price,oldPrice];
    NSString *p = price;
    NSString *op = oldPrice;
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:priceStr];
    [str addAttribute:NSForegroundColorAttributeName
                value:[UIColor colorWithRed:26/255.0 green:141/255.0 blue:255/255.0 alpha:1] range:NSMakeRange(0, p.length+1)];
    [str addAttribute:NSFontAttributeName
     
                value:[UIFont systemFontOfSize:18.0]
     
                range:NSMakeRange(0, p.length+1)];
    [str setAttributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(p.length + 2, op.length + 1)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(p.length + 1, op.length+2)];
    
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(p.length + 2, op.length + 1)];
    return str;
}
- (NSString*)weekDayStr:(NSString *)format
{
    NSString *weekDayStr = nil;
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    
    //    NSString *str = [self description];
    NSString *str = format;
    if (str.length >= 10) {
        NSString *nowString = [str substringToIndex:10];
        NSArray *array = [nowString componentsSeparatedByString:@"-"];
        if (array.count == 0) {
            array = [nowString componentsSeparatedByString:@"/"];
        }
        if (array.count >= 3) {
            int year = [[array objectAtIndex:0] intValue];
            int month = [[array objectAtIndex:1] intValue];
            int day = [[array objectAtIndex:2] intValue];
            [comps setYear:year];
            [comps setMonth:month];
            [comps setDay:day];
        }
    }
    
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *_date = [gregorian dateFromComponents:comps];
    NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:_date];
    int week = (int)[weekdayComponents weekday];
    
    switch (week) {
        case 1:
            weekDayStr = @"周日";
            break;
        case 2:
            weekDayStr = @"周一";
            break;
        case 3:
            weekDayStr = @"周二";
            break;
        case 4:
            weekDayStr = @"周三";
            break;
        case 5:
            weekDayStr = @"周四";
            break;
        case 6:
            weekDayStr = @"周五";
            break;
        case 7:
            weekDayStr = @"周六";
            break;
        default:
            weekDayStr = @"";
            break;
    }
    return weekDayStr;
}
-(NSAttributedString *)returnPriceStr:(NSString *)price {
    NSString *priceStr = [NSString stringWithFormat:@"￥%@",price] ;
    
    
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:priceStr];
    [str addAttribute:NSForegroundColorAttributeName
                value:[UIColor redColor] range:NSMakeRange(0, priceStr.length)];
    [str addAttribute:NSFontAttributeName
     
                value:[UIFont systemFontOfSize:17.0]
     
                range:NSMakeRange(0, priceStr.length)];
    [str addAttribute:NSFontAttributeName
     
                value:[UIFont systemFontOfSize:10.0]
     
                range:NSMakeRange(0, 1)];

    
    return str;
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if(alertView.tag == 10001)//检测手机
    {
        if (buttonIndex == 1) {
//            SendYanToOldViewController *lonView = [[SendYanToOldViewController alloc]init];
//            [self.navigationController pushViewController:lonView animated:YES];
        }

    }else{
        if (buttonIndex == 1) {
//            LoginViewController *lonView = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
//            [self.navigationController pushViewController:lonView animated:YES];
        }
    }
}


- (BOOL)isMobileNumber:(NSString *)mobileNum
{
    /**
     * 手机号码
     * 移动：134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     * 联通：130,131,132,152,155,156,185,186
     * 电信：133,1349,153,180,189
     */
    NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    /**
     10         * 中国移动：China Mobile
     11         * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
     12         */
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d{7}$";
    /**
     15         * 中国联通：China Unicom
     16         * 130,131,132,152,155,156,185,186
     17         */
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    /**
     20         * 中国电信：China Telecom
     21         * 133,1349,153,180,189
     22         */
    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    /**
     25         * 大陆地区固话及小灵通
     26         * 区号：010,020,021,022,023,024,025,027,028,029
     27         * 号码：七位或八位
     28         */
    // NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    
    if (([regextestmobile evaluateWithObject:mobileNum] == YES)
        || ([regextestcm evaluateWithObject:mobileNum] == YES)
        || ([regextestct evaluateWithObject:mobileNum] == YES)
        || ([regextestcu evaluateWithObject:mobileNum] == YES))
    {
        return YES;
    }
    else
    {
        return NO;
    }
}


//时间戳变换
-(NSString *)createdAt:(NSString *)createdTime{
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[createdTime floatValue]/1000];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    formatter.dateFormat = @"EEE MMM dd HH:mm:ss zzzz yyyy";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_cn"];
    
    //  NSDate *createTime = [formatter dateFromString:_createdAt];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
    NSString *createdTimeStr = [formatter stringFromDate:confromTimesp];
    
    
    
    NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:[formatter dateFromString:createdTimeStr]];
    
    NSTimeInterval second = time;
    NSTimeInterval minute = time / 60;
    NSTimeInterval hour = minute / 60;
    NSTimeInterval day = hour / 24;
    NSTimeInterval yue = day / 30;
    NSTimeInterval year = day / 365;
    
    if (second < 60) {
        return @"刚刚";
    }else if (minute <60){
        return [NSString stringWithFormat:@"%.f分钟前",minute];
    }else if (hour < 24){
        return [NSString stringWithFormat:@"%.f小时前",hour];
    }else if (day < 31){
        return [NSString stringWithFormat:@"%.f天前",day];
    } else if(yue < 12){
        return [NSString stringWithFormat:@"%.f月前",yue];
    }
    else if(year >= 1){
        formatter.dateFormat = @"yyyy-MM-dd";
        return [formatter stringFromDate:confromTimesp];
    }else{
        return createdTimeStr;
    }
    
}
#pragma mark 时间转换
-(NSString *)returnTimeWithString:(NSString *)createdTime andGeshi:(NSString *)fomatter{
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    
    formatter1.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_cn"];
    
    
    formatter1.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    
   
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
 
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_cn"];
    

    formatter.dateFormat = fomatter;
    
    NSDate *returnDate = [formatter1 dateFromString:createdTime];
   
    NSString *createdTimeStr = [formatter stringFromDate:returnDate];

    return createdTimeStr;
    
}
-(long long)returnShenYuTimeWith:(long long)endTimes{
    long long shenYuTime;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    formatter.dateFormat = @"EEE MMM dd HH:mm:ss zzzz yyyy";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_cn"];
   formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:endTimes/1000];

     NSString *createdTimeStr = [formatter stringFromDate:confromTimesp];
    
    NSTimeInterval nowTime = [[formatter dateFromString:createdTimeStr] timeIntervalSinceDate:[NSDate date]];
    
    shenYuTime = nowTime * 100;
    
    return shenYuTime + 100;
}




#pragma mark 发车时间比较
-(NSTimeInterval)returnTimeWithString:(NSString *)dateStr{
    
    
    NSDateFormatter *fomatter = [NSDateFormatter new];
    [fomatter setDateFormat:@"yyyy-MM-dd"];
    fomatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
    
//    NSString *nowStr = [fomatter stringFromDate:[NSDate date]];
    
    NSDateFormatter *fomatter1 = [NSDateFormatter new];
    [fomatter1 setDateFormat:@"yyyy-MM-dd HH:mm"];
    fomatter1.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
    
    NSDate *faCheDate = [fomatter1 dateFromString:dateStr];
    
    NSTimeInterval timeBetween = [faCheDate timeIntervalSinceNow];//返回给定时间和当前时间的时间差
    
    return timeBetween;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
